package com.freeSoft;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.sql.ResultSetMetaData;
import java.util.Properties;

public class CreateHeadJsp {
	private String tableName;
	private Properties prop;
	private ResultSetMetaData rs;
	private String basePath;
	private String baseJspName;
	public String getTableName() {
		return tableName;
	}
	public void setTableName(String tableName) {
		this.tableName = tableName;
	}
	public Properties getProp() {
		return prop;
	}
	public void setProp(Properties prop) {
		this.prop = prop;
	}
	public ResultSetMetaData getRs() {
		return rs;
	}
	public void setRs(ResultSetMetaData rs) {
		this.rs = rs;
	}
	public String getBasePath() {
		return basePath;
	}
	public void setBasePath(String basePath) {
		this.basePath = basePath;
	}
	
	public void createHeadJsp() {
//		String beanName = tableName.substring(0, 1).toUpperCase()+tableName.substring(1, tableName.length());
		baseJspName = "header.jsp";
		String outputDir = Util.getOutputDir(prop);
		String projectName = prop.getProperty(Util.PROJECT_NAME);
		basePath = outputDir+ projectName + File.separator+ projectName+ Util.WEB_NAME +File.separator+ 
		"src"+File.separator+"main"+File.separator+"webapp"+File.separator+projectName+File.separator;
		File f= new File(basePath);
		if ( !f.exists())
			f.mkdirs();
		try {
			
			PrintWriter out	   = new PrintWriter(new BufferedWriter( new FileWriter(basePath+baseJspName)));
			out.println("<%@ page language=\"java\" contentType=\"text/html; charset=utf-8\"    pageEncoding=\"utf-8\"%>");
//			out.println("<%@include file=\"header.jsp\"%>");
//			out.println("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">");
//			out.println("<html>");
//			out.println("<head>");
//			out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">");
//			out.println("<title>Add "+beanName +"</title>");
//			out.println("</head>");
//			out.println("<body>");
//			out.println("<form method=\"post\" action=\""+beanName+"\">");
//			for (int i = 1; i <= rs.getColumnCount(); i++) {
//				String fieldName = rs.getColumnName(i);
//				fieldName = fieldName.substring(0, 1).toUpperCase()	+ fieldName.substring(1, fieldName.length());
//				String typeName = rs.getColumnTypeName(i);
//				String fieldType = Util.changeJDBCTypeToJavaType(typeName);
//				if (fieldType.equals(""))
//					fieldType = Util.getDataType(rs.getColumnType(i), rs.getScale(i));
//				out.println(fieldName+":<input type=\"text\"  name=\""+fieldName+"\" id=\""+fieldName+"\"><br/>");
//				
//			}
//			out.print("<input type=\"button\"  value=\"Save\"/>&nbsp;");
//			out.println("<input type=\"button\"  value=\"reset\"/>");
//			out.println("</form>");
//			out.println("</body>");
//			out.println("</html>");		
			out.flush();
			out.close();
		} catch (Exception e) {

		}
	}
}
